﻿<html dir="LTR"><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><title>LockGuard Structure</title><xml></xml><link rel="stylesheet" type="text/css" href="MSDN.css"></head><body id="bodyID" class="dtBODY"><div id="nsbanner"><div id="bannerrow1"><table class="bannerparthead" cellspacing="0"><tr id="hdr"><td class="runninghead">An NDoc Documented Class Library</td><td class="product"></td></tr></table></div><div id="TitleRow"><h1 class="dtH1">LockGuard Structure</h1></div></div><div id="nstext"><p>
            The LockGuard structure marks a statement block as a critical section by 
            obtaining the mutual-exclusion lock for a given object, executing a statement block, 
            and then releasing the lock when disposed.
            </p><p>For a list of all members of this type, see <a href="ELS.Configuration.LockGuardMembers.html">LockGuard Members</a>.</p><p><a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemObjectClassTopic.htm">System.Object</a><br>   <a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemValueTypeClassTopic.htm">ValueType</a><br>      <b>LockGuard</b></p><div class="syntax"><div>public struct LockGuard : IDisposable</div></div><h4 class="dtH4">Remarks</h4>
            The LockGuard structure implements the RAII pattern and abstracts the need for writing 
            a try,catch, finally blocks around a critical section.
            <p>The LockGuard uses a <a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemThreadingMonitorClassTopic.htm">Monitor</a>.<a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemThreadingMonitorClassTryEnterTopic.htm">TryEnter</a> instead of a 
            <a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemThreadingMonitorClassTopic.htm">Monitor</a>.<a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemThreadingMonitorClassEnterTopic.htm">Enter</a>
            to avoid scenarios where the code will block indefinitely (deadlock) because the monitor is unavailable. </p><p>The default timeout to acquire an exclusive lock is 600000 milliseconds.</p><h4 class="dtH4">Example</h4><p><pre class="code">
            using ( new LockGuard ( objectToLock ) )
            {
            	// your code goes here...
            }
            </pre></p><h4 class="dtH4">Requirements</h4><p><b>Namespace: </b><a href="ELS.Configuration.html">ELS.Configuration</a></p><p><b>Assembly: </b>Configuration.Core (in Configuration.Core.dll)
					</p><h4 class="dtH4">See Also</h4><p><a href="ELS.Configuration.LockGuardMembers.html">LockGuard Members</a> | <a href="ELS.Configuration.html">ELS.Configuration Namespace</a></p><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e" viewastext="true" style="display: none;"><param name="Keyword" value="LockGuard structure, about LockGuard structure"></object></div></body></html>